package com.jessechanrui.template.common.template.auth.config;

import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.info.Info;
import io.swagger.v3.oas.models.security.SecurityRequirement;
import io.swagger.v3.oas.models.security.SecurityScheme;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @author chenrui
 * @version 1.0
 * @description SwaggerConfiguration
 * @date 2025/5/6
 */
@Configuration
public class SwaggerConfiguration {
    @Bean
    public OpenAPI customOpenAPI() {
        // 定义安全模式（Bearer Token）
        SecurityScheme bearerScheme = new SecurityScheme()
                .type(SecurityScheme.Type.HTTP)
                .scheme("bearer")
                .bearerFormat("JWT")
                .in(SecurityScheme.In.HEADER)
                .name("Authorization");

        SecurityRequirement securityRequirement = new SecurityRequirement().addList("BearerAuth");
        return new OpenAPI()
                .info(new Info()
                        .title("aicr console API 文档")
                        .description("aicr console API 文档。")
                        .version("1.0.0"))
                .addSecurityItem(securityRequirement) // 全局应用安全规则
                .components(new Components().addSecuritySchemes("BearerAuth", bearerScheme));
    }
}
